package com.example.accessingdatamysql;

import com.example.accessingdatamysql.first.User;
import com.example.accessingdatamysql.first.UserMapper;
//import com.example.accessingdatamysql.first.UserRepository;
import com.example.accessingdatamysql.second.Msg;
import com.example.accessingdatamysql.second.MsgMapper;
//import com.example.accessingdatamysql.second.MsgRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Iterator;

/**
 * @author caiwl
 * @date 2020/4/3 8:52
 */
@Controller // This means that this class is a Controller
@RequestMapping(path="/demo") // This means URL's start with /demo (after Application path)
public class MainController {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private MsgMapper msgMapper;

    @GetMapping(path="/all")
    public @ResponseBody Iterable<User> getAllUsers2() {
        // This returns a JSON or XML with the users
        return userMapper.selectAll();
    }

    @GetMapping(path="/msg")
    public @ResponseBody Iterable<Msg> getAllMsgs2() {
        return msgMapper.selectAll();
    }
}
